package com.pica.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.pica.common.annotation.Log;
import com.pica.common.enums.BusinessType;
import com.pica.system.domain.Evaluate;
import com.pica.system.service.IEvaluateService;
import com.pica.common.core.controller.BaseController;
import com.pica.common.core.domain.AjaxResult;
import com.pica.common.utils.poi.ExcelUtil;
import com.pica.common.core.page.TableDataInfo;

/**
 * 面试评价Controller
 * 
 * @author 徐鑫杰
 * @date 2022-12-14
 */
@Controller
@RequestMapping("/system/evaluate")
public class EvaluateController extends BaseController
{
    private String prefix = "system/evaluate";

    @Autowired
    private IEvaluateService evaluateService;

    @RequiresPermissions("system:evaluate:view")
    @GetMapping()
    public String evaluate()
    {
        return prefix + "/evaluate";
    }

    /**
     * 查询面试评价列表
     */
    @RequiresPermissions("system:evaluate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Evaluate evaluate)
    {
        startPage();
        List<Evaluate> list = evaluateService.selectEvaluateList(evaluate);
        return getDataTable(list);
    }

    /**
     * 导出面试评价列表
     */
    @RequiresPermissions("system:evaluate:export")
    @Log(title = "面试评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Evaluate evaluate)
    {
        List<Evaluate> list = evaluateService.selectEvaluateList(evaluate);
        ExcelUtil<Evaluate> util = new ExcelUtil<Evaluate>(Evaluate.class);
        return util.exportExcel(list, "面试评价数据");
    }

    /**
     * 新增面试评价
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存面试评价
     */
    @RequiresPermissions("system:evaluate:add")
    @Log(title = "面试评价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Evaluate evaluate)
    {
        return toAjax(evaluateService.insertEvaluate(evaluate));
    }

    /**
     * 修改面试评价
     */
    @RequiresPermissions("system:evaluate:edit")
    @GetMapping("/edit/{evaId}")
    public String edit(@PathVariable("evaId") Long evaId, ModelMap mmap)
    {
        Evaluate evaluate = evaluateService.selectEvaluateByEvaId(evaId);
        mmap.put("evaluate", evaluate);
        return prefix + "/edit";
    }


    /**
     * 修改面试评价 按钮跳转到面试管理页面
     */
    @RequiresPermissions("system:evaluate:edit")
    @GetMapping("/evaluate/{evaId}")
    public String evaluate(@PathVariable("evaId") Long evaId, ModelMap mmap)
    {
        Evaluate evaluate = evaluateService.selectEvaluateByEvaId(evaId);
        mmap.put("evaluate", evaluate);
        return prefix + "/edit";
    }

    /**
     * 修改保存面试评价 更新面试官的表单提交操作
     */
    @RequiresPermissions("system:evaluate:edit")
    @Log(title = "面试评价", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Evaluate evaluate)
    {

        return toAjax(evaluateService.updateEvaluate(evaluate));
    }

    /**
     * 删除面试评价
     */
    @RequiresPermissions("system:evaluate:remove")
    @Log(title = "面试评价", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(evaluateService.deleteEvaluateByEvaIds(ids));
    }
}
